from machine import FPIOA
from machine import PWM
import time

beep_io = FPIOA()

beep_io.set_function(43, FPIOA.PWM1)
#beep_io.set_function(25, FPIOA.PWM5)

beep = PWM(1, 500, 20, enable=False)



notes = {
         'C4':261,
         'D4':293,
         'E4':329,
         'F4':349,
         'G4':392,
         'A4':440,
         'B4':493,
         'C5':523,
}

melody = [
    ('C4', 500),('C4', 500),('G4', 500),('G4', 500),
    ('A4', 500),('A4', 500),('G4', 1000),
    ('F4', 500),('F4', 500),('E4', 500),('E4', 500),
    ('D4', 500),('D4', 500),('C4', 1000),
]

def play_tone(note, duration):
    frequency = notes.get(note, 0)
    if frequency > 0:
        beep.freq(frequency)
        beep.enable(True)
        time.sleep_ms(duration)
        beep.enable(False)
        time.sleep_ms(50)


for note, duration in melody:
    play_tone(note, duration)


beep.deinit()
'''
beep.enable(1)
time.sleep_ms(50)
beep.enable(0)
beep.deinit()
'''


